{extend name="$base" /}
{block name="resources"}
<link rel="stylesheet" type="text/css" href="ADMIN_CSS/member_list.css" />
<script type="text/javascript" src="__STATIC__/My97DatePicker/WdatePicker.js"></script>

{/block}
{block name="main"}
<div class="set-style">
	<dl>
		<dt><span class="required">*</span>发布者:</dt>
		<dd>
			<input type="number" id="post_uid" value="">
			<p class="error">请填写发布者</p>
			<p class="hint">设置发布者</p>
		</dd>
	</dl>
	<dl>
		<dt><span class="required">*</span>状态:</dt>
		<dd>
			<input type="number" id="trade_type" value="">
			<p class="error">请输入数量</p>
			<p class="hint">设置数量</p>
		</dd>
	</dl>
	<dl>
		<dt><span class="required">*</span>类型:</dt>
		<dd>
			<input type="number" id="trade_status" value="">
			<p class="error">请输入数量</p>
			<p class="hint">设置数量</p>
		</dd>
	</dl>
	<dl>
		<dt><span class="required">*</span>数量:</dt>
		<dd>
			<input type="number" id="coin_count" value="">
			<p class="error">请输入数量</p>
			<p class="hint">设置数量</p>
		</dd>
	</dl>
	<dl>
		<dt><span class="required">*</span>金额:</dt>
		<dd>
			<input type="number" id="coin_price" value="">
			<p class="error">请输入金额</p>
			<p class="hint">设置金额</p>
		</dd>
	</dl>
	<dl>
		<dt><span class="required">*</span>发布日期:</dt>
		<dd>
			<input type="date" id='add_time' placeholder="请选择日期" class="input-medium" />
			<p class="error">请选择日期</p>
			<p class="hint">设置日期</p>
		</dd>
	</dl>
	<dl>
		<dt><span class="required">*</span>交易日期:</dt>
		<dd>
			<input type="date" id='trade_time' placeholder="请选择日期" class="input-medium" />
			<p class="error">请选择日期</p>
			<p class="hint">设置日期</p>
		</dd>
	</dl>
	<dl>
		<dt><span class="required">*</span>完成交易日期:</dt>
		<dd>
			<input type="date" id='finish_time' placeholder="请选择日期" class="input-medium" />
			<p class="error">请选择日期</p>
			<p class="hint">设置日期</p>
		</dd>
	</dl>
	<button class="edit_button" onclick="addGift()">提交</button>
</div>
{/block}

{block name="script"}
<script type="text/javascript">
     var flag = false;//防止重复提交

	 //保存
	function addGift(){
	    console.log("保存数据");

        var post_uid = $("#post_uid").val();
        var trade_status = $("#trade_status").val();
        var trade_type = $("#trade_type").val();
		var coin_count = $("#coin_count").val();
        var coin_price = $("#coin_price").val();
        var add_time = $("#add_time").val();
        var trade_time = $("#trade_time").val();
        var finish_time = $("#finish_time").val();

		if (coin_count == '') {
			$("#coin_count").next().show().css("display","inline-block");
			$("#coin_count").focus();
			return false;
		} else {
			$(".error").hide();
		}

        if (post_uid == '') {
            $("#post_uid").next().show().css("display","inline-block");
            $("#post_uid").focus();
            return false;
        } else {
            $(".error").hide();
        }

        if (trade_status == '') {
            $("#trade_status").next().show().css("display","inline-block");
            $("#trade_status").focus();
            return false;
        } else {
            $(".error").hide();
        }
        if (trade_type == '') {
            $("#trade_type").next().show().css("display","inline-block");
            $("#trade_type").focus();
            return false;
        } else {
            $(".error").hide();
        }

        if (coin_price == '') {
            $("#coin_price").next().show().css("display","inline-block");
            $("#coin_price").focus();
            return false;
        } else {
            $(".error").hide();
        }

        if (add_time == '') {
            $("#add_time").next().show().css("display","inline-block");
            $("#add_time").focus();
            return false;
        } else {
            $(".error").hide();
        }

        if (trade_time == '') {
            $("#trade_time").next().show().css("display","inline-block");
            $("#trade_time").focus();
            return false;
        } else {
            $(".error").hide();
        }

        if (finish_time == '') {
            $("#finish_time").next().show().css("display","inline-block");
            $("#finish_time").focus();
            return false;
        } else {
            $(".error").hide();
        }


		if(flag){
			return false;
		}
		flag = true;
		$.ajax({
			type : "post",
			url : "ADMIN_MAIN/mine/addCoinTrade",
			data : {
                'post_uid': post_uid,
                'trade_type': trade_type,
				'trade_status':trade_status,
                'coin_count': coin_count,
                'coin_price': coin_price,
                'add_time': add_time,
                'trade_time': trade_time,
                'finish_time': finish_time
			},
			async : true,
			success : function(data) {
				if (data["code"] > 0) {
					showMessage('success', data["message"]);
					 location.href="ADMIN_MAIN/Mine/TradeList";
				}else{
					showMessage('error', data["message"]);
				}	
				flag = false;
			}
		});
	}
</script>
{/block}